package md.rdcrng.cvs;

import java.io.Serializable;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;

/**
 <p/>
 @param <T> <p/>
 @author Radu Creanga <rdcrng@gmail.com>
 */
class Component<T> implements Serializable {

    private static final long serialVersionUID = 42L;
    private final T instance;
    private final Contextual<T> contextual;
    private final CreationalContext<T> creationalContext;

    protected Component(Contextual<T> contextual, CreationalContext<T> creationalContext) {
        this.contextual = contextual;
        this.creationalContext = creationalContext;
        this.instance = this.contextual.create(this.creationalContext);
    }

    protected T getInstance() {
        return this.instance;
    }

    protected void destroy() {
        this.contextual.destroy(this.instance, this.creationalContext);
    }

}
